<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/7/24
 * Time: 10:50
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\lib\upload;


use think\Exception;
use think\exception\ValidateException;
use think\facade\Filesystem;
use think\facade\Log;

class Base
{
    /**
     * @return array
     * @throws Exception
     */
    public function upload(): array
    {

        $files = request()->file();
        //halt($files);
        if (!$this->validateObj->scene('image')->check($files)) {
            throw new Exception($this->validateObj->getError());
        }
        try {
            $saveName = [];
            foreach ($files as $key => $file) {
                $path = Filesystem::disk('public')->putFile('upload/' . $key, $file);
                $saveName[] = $path;
            }
        } catch (\Exception $e) {
            Log::error($e->getMessage() . " " . $e->getFile() . " " . $e->getLine());
            throw new Exception("内部错误");
        }
        return $saveName;
    }
}